package com.example.dadong.checkwordview;

import android.Manifest;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.widget.Button;

import com.example.library.RequestBack;
import com.example.library.RequestKnowledgeEntity;
import com.example.library.http.KnowledgeEntity;
import com.example.library.http.KnowledgeParseBaseUrl;
import com.example.library.view.CheckWordTextView;
import com.lancoo.evaluate.util.permission.PermissionsManager;
import com.lancoo.evaluate.util.permission.PermissionsResultAction;
import com.orhanobut.logger.Logger;

import java.util.List;


public class TestCheckActivity extends AppCompatActivity {
    CheckWordTextView mEnglishGetWordTextView;
    Button tv;
    String text = "I'm still. very much figuring out what." +
            " I want to do with my life,I'm still. very much" +
            " figuring out what. I want to do with my life";
    RequestKnowledgeEntity requestKnowledgeEntity;
    RequestBack<List<KnowledgeEntity>> entityRequestBack;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    private void init() {
        KnowledgeParseBaseUrl.setBaseUrl("http://60.190.136.238:2048/");
        mEnglishGetWordTextView = findViewById(R.id.english_get_word_text_view);

        entityRequestBack = new RequestBack<List<KnowledgeEntity>>() {
            @Override
            public void onSuccess(List<KnowledgeEntity> knowledgeEntity) {
                if (knowledgeEntity != null) {
                    mEnglishGetWordTextView.setHighLightColor(Color.RED);
                    mEnglishGetWordTextView.setKnowledgeEntitys(knowledgeEntity);
                    mEnglishGetWordTextView.setmACtivity(TestCheckActivity.this, getSupportFragmentManager(), "S2-666-E421","B","restu13" );
                    mEnglishGetWordTextView.setText(Html.fromHtml(text).toString());
                    mEnglishGetWordTextView.invalidate();
                }
            }

            @Override
            public void onErr(Throwable e) {
                Logger.d("fuck the code" + "shishi2");
            }

        };
        requestKnowledgeEntity = new RequestKnowledgeEntity(this, entityRequestBack);
        requestKnowledgeEntity.getData(text.toString(), "B");

        requestAllPermissions();
    }

    private void requestAllPermissions() {
        PermissionsManager.getInstance().requestPermissionsIfNecessaryForResult(this,
                new String[]{Manifest.permission.RECORD_AUDIO, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, new PermissionsResultAction() {
                    @Override
                    public void onGranted() {
                    }

                    @Override
                    public void onDenied(String permission) {
                    }
                });
    }
}
